<!-- 我的弹窗 -->

<template>
  <WebModal>
    <WebForm class="ScheduleQueue-MyModal-form">
      <EasyRow col2>
        <FormInput label="班次名称" bind="scheduleName" :max="20" required />
        <FormStatus isRadio />
      </EasyRow>

      <EasyRow col2>
        <FormDateRange label="排班日期" bind="scheduleBegin, scheduleEnd" required />
        <FormSlot label="执行员工" bind="userIds" tipPre="请选择" required>
          <ModalUser />
        </FormSlot>
      </EasyRow>

      <EasyRow col4>
        <FormSelect label="班次类型" bind="scheduleType" :dict="DICT.TYPE" noClear @change="changeType" />
        <FormSelect
          v-if="one.scheduleType === 2"
          label="循环天数"
          bind="cycleNum"
          :dict="DICT.DAYS"
          initFirst
          noClear
          @change="changeNum"
        />
        <FormSelect
          v-if="one.scheduleType === 2"
          label="法定节假日"
          bind="include"
          :dict="DICT.INCLUDE"
          initFirst
          noClear
        />
        <FormSlot v-if="one.scheduleType === 2" noLabel isTip>{{ TIP_HOLIDAY }}</FormSlot>
      </EasyRow>

      <FormSlot noLabel>
        <ModalCycle />
      </FormSlot>

      <FormTextarea label="备注" bind="description" :max="100" :rows="2" />
    </WebForm>
  </WebModal>
</template>

<script>
// ============================== 导入依赖 ============================== //

import CORE from '@/CORE'

// ============================== 导出组件 ============================== //

export default {
  /**
   * 名称定义 (实际使用名称)
   */
  name: 'MyModal',

  /**
   * 混入列表 (配置选项合并)
   */
  mixins: [CORE.mixWeb()],

  /**
   * 组件导入 (Abc.vue + Abc/index.vue)
   */
  ...CORE.components(require.context('./', true, /vue$/)),

  /**
   * 计算属性 (慎用箭头函数)
   */
  computed: {
    /**
     * 类型提示语
     */
    TIP_TYPE: () => '',

    /**
     * 节假日提示语
     */
    TIP_HOLIDAY: () => '不包含则跳过法定节假日',
  },

  /**
   * 本地方法 (轻量重要在前)
   */
  methods: {
    /**
     * 切换类型
     */
    changeType(type) {
      const { one } = this
      if (type === 1) Object.assign(one, { cycles: [one.cycles[0]], cycleNum: 1, include: 1 })
    },

    /**
     * 切换天数
     */
    changeNum(num) {
      const { INIT_ONE, one } = this

      const EMPTY = Array(num).fill().map(() => CORE.merge({}, INIT_ONE.cycles[0], { key: CORE.fileName() }))
      one.cycles = [...one.cycles, ...EMPTY].slice(0, num)
    },
  },
}
</script>

<style lang="scss">
@import './index.scss';
</style>
